function [ EC ] = APEramanshift( datasetname, exwavelength, reverse )
% [ EC ] = APEramanshift( datasetname, exwavelength )
%
%   Converts the raw datax in datasetname from assumed wavelength in nm to
%   Raman shift in cm^-^1 using the Laser Excitation Wavelength
%   exwavelength in nm.
%   The result will be saved in the same file as ramandatax.
%
% INPUT     datasetname     :   file name to process
%           exwavelength    :   Laser excitation wavelength in nm
%           reverse         :   if set ramashift will be converted back to
%                                 wavelength
%
% OUTPUT            EC      :   Error Code. (0=success, 1=error)

% DEPENDENCIES              - ramashift.m

%  (c) F. Dworkowski, 2012
%      Version 1.1, 2012-06-20


%% ===== Config =====
EC = 0;

%% ===== CODE =====
% ----- check for input argument -----
 
if nargin<2,
    help APEramanshift
    EC = 1;
    return
elseif nargin == 2,
    reverse = 0;
else
    reverse = 1;
end

try dset=load(datasetname);
catch ME
  errordlg('ERROR: file not found in "APEmat2asc"!')
      EC = 1;
  return
end

if reverse == 1
    if isfield(dset,'ramandatax')
        dset.datax = ramanshift_rev(dset.ramandatax, exwavelength);
    else
        dset.original_datax = dset.datax;
        dset.datax = ramanshift_rev(dset.original_datax, exwavelength);
    end
    dset.Laser_exwavelength = exwavelength;
else
    dset.ramandatax = ramanshift(dset.datax, exwavelength);
    dset.Laser_exwavelength = exwavelength;
end

save(datasetname,'-struct','dset')

    EC = 0;

end

